"""
登录页面
"""
from selenium.webdriver.common.by import By

from untils import DriverUtil


class LoginPage(object):
    """登录对象层"""

    def __init__(self):
        self.driver = DriverUtil.get_driver()

    def find_username(self):
        """定位用户name方法"""
        return self.driver.find_element(By.ID, 'usernamem')

    def find_pwd(self):
        """定位用户pwd方法"""
        return self.driver.find_element(By.ID, 'pwd')

    def find_verify_code(self):
        """定位验证码"""
        return self.driver.find_element(By.ID, 'code')

    def find_login_btn(self):
        """定位登录按钮"""
        return self.driver.find_element(By.ID, 'btn')


class LoginHandle(object):
    """登录操作层"""

    def __init__(self):
        self.login_page = LoginPage()

    def input_username(self, name):
        self.login_page.find_username().send_keys(name)

    def input_pwd(self, pwd):
        self.login_page.find_pwd().send_keys(pwd)

    def input_verify_code(self, code):
        self.login_page.find_verify_code().send_keys(code)

    def click_login_btn(self):
        self.login_page.find_login_btn().click()


class LoginTask(object):
    # 登录业务层
    def __init__(self):
        self.login_handle = LoginHandle()

    def login_method(self, name, pwd, code):
        self.login_handle.input_username(name)
        self.login_handle.input_pwd(pwd)
        self.login_handle.input_verify_code(code)
        self.login_handle.click_login_btn()
